package com.ch.swagger2.controller.commond;

import com.ch.swagger2.model.Response;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author cj-ch
 * @date 2018/5/2 下午7:48
 */
@RestController
@RequestMapping("/commond")
@Api(value = "通用接口", tags = {"公共"}, description = "")
public class CommondController {

    /*
        @ApiOperation注解说明:
        value - 接口名称
        notes - 接口注释
                有关于接口版本变更记录也是追加到这里,从V2版本开始记录,填写规范按照我给的例子,
                {版本}&emsp;{修改内容}&emsp;{修改人员}<hr>
                "&emsp;"表示4个空格,这里支持简单的html元素
        consumes - 描述接口请求头contentType类型
     */
    @ApiOperation(value = "文件上传接口",
            notes = "如果接口需要详细描述可以写在这里<hr>" +
                    "版本变更记录<hr>" +
                    "V2&emsp;添加了meteData参数&emsp;张三<hr>" +
                    "V3&emsp;添加了other参数&emsp;李四<hr>" +
                    "V4&emsp;添加了XXXX参数&emsp;李四<hr>",
            consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    /*
        @ApiImplicitParams和@ApiImplicitParam注解说明:
        @ApiImplicitParams可以包含多个@ApiImplicitParam,@ApiImplicitParams用于注解多个请求参数,@ApiImplicitParam用于注解单个请求参数
        @ApiImplicitParam不能对@RequestBody注解的参数及表单文件参数进行注解,否则,接口文档生成有问题
        @ApiImplicitParam注解说明:
            name - 参数名称
            value - 参数描述(尽量描述到位,语义详尽)
            required - 是否比填,默认false
            paramType - 参数类型,示例:Valid values are {@code path}, {@code query}, {@code body},{@code header} or {@code form}.
            dataType - 参数数据类型,默认String,数据类型是数值类型是必填
            allowableValues - 参数可填值范围
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "meteData", value = "上传类型", required = true, paramType = "form", allowableValues = "1,2,3"),
            @ApiImplicitParam(name = "other", value = "其他", required = false, paramType = "form", dataType = "string")
    })
    @PostMapping("/file/upload")
    public Response fileUpload(@RequestPart(value = "file") MultipartFile file,
                               @RequestParam(value = "meteData") String meteData,
                               @RequestParam(value = "other", required = false) String other) {
        System.out.println("上传文件:" + file.getOriginalFilename());
        System.out.println("meteData=" + meteData);
        System.out.println("other=" + other);
        return Response.success();
    }


}
